import sqlite3

# 建立数据库
conn = sqlite3.connect("test.db")
# 创建游标
cursor = conn.cursor()
# # 创建表
# cursor.execute("create table user(id integer(11) primary key,name varchar(20))")
# conn.commit()

# 插入数据
# sql = "insert into user values(1,'root')"
# sql2 = "insert into user values(?,?)"
# cursor.execute(sql2,(2,"admin"))
# conn.commit()

# 查询数据
sql = "select * from user"
cursor.execute(sql)
for row in cursor:
    # 打印用户名 row[0]代表第一行
    print(row[1])

result = cursor.execute(sql).fetchall()
for row in result:
    print(row)